{extend name='common/_container'} {block name="content"}
<div class="row">
	<div class="col-sm-12">
		<div class="ibox float-e-margins">
			<div class="ibox-title">
				<h5>业务所得</h5>
				<button style="float:right; margin-top:-10px;" title="刷新页面" type="button" class="btn btn-default btn-outline" onclick="window.location.reload()" id="">
					<i class="fa fa-refresh"></i>
				</button>
			</div>
			<div class="ibox-content">
				<div class="row row-lg">
					<div class="col-sm-12">
						<div class="row" id="searchGroup">
							<div class="col-sm-3">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">客户身份证</button>
									</div>
									<input type="text" class="form-control" id="customer_idcard" placeholder="客户身份证" />
								</div>
							</div>
							<div class="col-sm-3">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">承办人</button>
									</div>
									<select class="form-control" id="director_id" name="director_id">
										<option value="">--请选择--</option>
										{volist name='director_list' id='item'}
											<option value="{$item.user_id}">{$item.name}</option>
										{/volist}
									</select>
								</div>
							</div>

							<script src="__PUBLIC__/static/js/plugins/shengshiqu/distpicker.data.js"></script>
							<script src="__PUBLIC__/static/js/plugins/shengshiqu/distpicker.js"></script>
							<script src="__PUBLIC__/static/js/plugins/shengshiqu/main.js"></script>
							<div class="col-sm-3">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">起始时间</button>
									</div>
									<input type="text" autocomplete="off" placeholder="起始时间" class="form-control layer-date" onclick="laydate({istime: true})" id="start_time">
								</div>
							</div>
							<div class="col-sm-3">
								<div class="input-group">
									<div class="input-group-btn">
										<button data-toggle="dropdown" class="btn btn-white dropdown-toggle" type="button">结束时间</button>
									</div>
									<input type="text" autocomplete="off" placeholder="结束时间" class="form-control layer-date" onclick="laydate({istime: true})" id="end_time">
								</div>
							</div>
							<!-- search end -->
							<div class="col-sm-2">
									<button type="button" class="btn btn-primary " onclick="CodeGoods.search()" id="">
										<i class="fa fa-search"></i>&nbsp;搜索
									</button>
							</div>
						</div>
						<div class="btn-group-sm" id="CodeGoodsTableToolbar" role="group">
							<button type="button" id="sd_deal" class="btn btn-primary button-margin" onclick="CodeGoods.sd_deal()">
								<i class="fa fa-dollar"></i>&nbsp;结算
							</button>
						</div>
						<table id="CodeGoodsTable" data-mobile-responsive="true" data-click-to-select="true">
							<thead><tr><th data-field="selectItem" data-checkbox="true"></th></tr></thead>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
	var CodeGoods = {id: "CodeGoodsTable",seItem: null,table: null,layerIndex: -1};

	CodeGoods.initColumn = function () {
 		return [
		 	{field: 'selectItem', checkbox: true},
			{title: '编号', field: 'id', visible: true, align: 'center', valign: 'middle'},
			{title: '身份证', field: 'id_card', visible: true, align: 'center', valign: 'middle'},
			// {title: '姓名', field: 'full_name', visible: true, align: 'center', valign: 'middle'},
			// {title: '电话', field: 'mobile', visible: true, align: 'center', valign: 'middle'},
			{title: '承办人', field: 'director_name', visible: true, align: 'center', valign: 'middle'},
			{title: '介绍人', field: 'is_introducer', visible: true, align: 'center', valign: 'middle',formatter:CodeGoods.isNotFormatter},
			{title: '总费用', field: 'total_fee', visible: true, align: 'center', valign: 'middle'},
			// {title: '调身份证<br/>资料费', field: 'id_card_fee', visible: true, align: 'center', valign: 'middle'},
			// {title: '调护照资<br/>料费', field: 'pass_port_fee', visible: true, align: 'center', valign: 'middle'},
			// {title: '身份证认<br/>证费', field: 'id_card_certification_fee', visible: true, align: 'center', valign: 'middle'},
			// {title: '护照认证<br/>费用', field: 'pass_port_certification_fee', visible: true, align: 'center', valign: 'middle'},
			// {title: '身份证领<br/>事馆费用', field: 'id_card_lsg_fee', visible: true, align: 'center', valign: 'middle'},
			// {title: '护照领事<br/>馆费用', field: 'pass_port_lsg_fee', visible: true, align: 'center', valign: 'middle'},
			{title: '入款金额', field: 'lbj_fee', visible: true, align: 'center', valign: 'middle'},
			{title: '业务所得', field: 'business_income_amount', visible: true, align: 'center', valign: 'middle',formatter:CodeGoods.BusinessIncomeAmountFormatter},
			{title: '代付费用', field: 'pay_for_amount', visible: true, align: 'center', valign: 'middle',formatter:CodeGoods.payForAmountFormatter},
			{title: '时间', field: 'created_time_text', visible: true, align: 'center', valign: 'middle'}
 		];
 	};

	CodeGoods.buttonFormatter = function(value,row,index) {
		if(value){
			var str= '';
			str += '<button type="button" class="btn btn-success btn-xs" title="修改"  onclick="CodeGoods.update('+value+')"><i class="fa fa-pencil"></i>&nbsp;修改</button>&nbsp;'
			str += '<button type="button" class="btn btn-danger btn-xs" title="删除"  onclick="CodeGoods.delete('+value+')"><i class="fa fa-trash"></i>&nbsp;删除</button>&nbsp;'
			str += '<button type="button" class="btn btn-danger btn-xs" title="查看"  onclick="CodeGoods.view('+value+')"><i class="fa fa-trash"></i>&nbsp;查看</button>&nbsp;'
			return str;
		}
	}

	CodeGoods.isNotFormatter = function(value,row,index) {
		if(value !== null){
			var value = value.toString();
			switch(value){
				case '1':
					return '<span class="label label-success">是</span>';
				break;
				case '2':
					return '<span class="label label-warning">否</span>';
				break;
			}
		}
	}

	CodeGoods.idCardFormatter = function(value,row,index) {
		if(value){
			return "<a href=\"javascript:void(0)\" onclick=\"openImg('"+value+"')\"><img height='30' src="+value+"></a>";
		}
	}

	CodeGoods.amountFormatter = function(value,row,index) {
		if(value){
			return '<span class="label label-info">'+value+'</span>';
		}
	}

	CodeGoods.statusFormatter = function(value,row,index) {
		if(value !== null){
			if(value == 1){
				return '<input class="mui-switch mui-switch-animbg status'+row.id+'" type="checkbox" onclick="CodeGoods.updatestatus('+row.id+',0)" checked>';
			}else{
				return '<input class="mui-switch mui-switch-animbg status'+row.id+'"  type="checkbox" onclick="CodeGoods.updatestatus('+row.id+',1)">';
			}
		}
	}

	CodeGoods.payForAmountFormatter = function(value,row,index) {
		return '<input type="text" class="form-control" id="pay_for_fee_'+row.id+'" value="8000" />';
	}

	CodeGoods.BusinessIncomeAmountFormatter = function(value,row,index) {
		return '<input type="text" class="form-control" id="business_income_amount_'+row.id+'" value="'+value+'" />';
	}



	CodeGoods.updatestatus = function(pk,value) {
		var ajax = new $ax(Feng.ctxPath + "/Member/updateExt", function (data) {
			if ('00' === data.status) {
			} else {
				Feng.error(data.msg);
				$(".status"+pk).prop("checked",!$(".status"+pk).prop("checked"));
			}
		});
		var val = $(".status"+pk).prop("checked") ? 1 : 0;
		ajax.set('id', pk);
		ajax.set('status', value);
		ajax.start();
	}

	CodeGoods.create_timeFormatter = function(value,row,index) {
		if(value){
			return formatDateTime(value);
		}
	}

	CodeGoods.formParams = function() {
		var queryData = {};
		queryData['customer_idcard'] = $("#customer_idcard").val();
		queryData['director_id'] = $("#director_id").val();
		// queryData['customer_passort'] = $("#customer_passort").val();
		queryData['start_time'] = $("#start_time").val();
		queryData['end_time'] = $("#end_time").val();
		return queryData;
	}

	CodeGoods.check = function () {
		var selected = $('#' + this.id).bootstrapTable('getSelections');
		if(selected.length == 0){
			Feng.info("请先选中表格中的某一记录！");
			return false;
		}else{
			CodeGoods.seItem = selected;
			return true;
		}
	};

	CodeGoods.updateExt = function (value) {
	}


	CodeGoods.add = function (value) {
		var url = location.search;
		var index = layer.open({type: 2,title: '添加',area: ['100%', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/Record.Customer/add'+url});
		this.layerIndex = index;
	}


	CodeGoods.update = function (value) {
		if(value){
			var index = layer.open({type: 2,title: '修改',area: ['100%', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/Record.Customer/update?id='+value});
		}else{
			if (this.check()) {
				var idx = '';
				$.each(CodeGoods.seItem, function() {
					idx += ',' + this.id;
				});
				idx = idx.substr(1);
				if(idx.indexOf(",") !== -1){
					Feng.info("请选择单条数据！");
					return false;
				}
				var index = layer.open({type: 2,title: '修改',area: ['100', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/Record.Customer/update?id='+idx});
				this.layerIndex = index;
			}
		}
	}


	CodeGoods.delete = function (value) {
		if(value){
			Feng.confirm("是否删除选中项？", function () {
				var ajax = new $ax(Feng.ctxPath + "/Record.Customer/delete", function (data) {
					if ('00' === data.status) {
						Feng.success(data.msg);
						CodeGoods.table.refresh();
					} else {
						Feng.error(data.msg);
					}
				});
				ajax.set('ids', value);
				ajax.start();
			});
		}else{
			if (this.check()) {
				var idx = '';
				$.each(CodeGoods.seItem, function() {
					idx += ',' + this.id;
				});
				idx = idx.substr(1);
				Feng.confirm("是否删除选中项？", function () {
					var ajax = new $ax(Feng.ctxPath + "/Record.Customer/delete", function (data) {
						if ('00' === data.status) {
							Feng.success(data.msg);
							CodeGoods.table.refresh();
						} else {
							Feng.error(data.msg);
						}
					});
					ajax.set('ids', idx);
					ajax.start();
				});
			}
		}
	}


	CodeGoods.view = function (value) {
		if(value){
			var index = layer.open({type: 2,title: '查看数据',area: ['800px', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/Record.Customer/view?id='+value});
		}else{
			if (this.check()) {
				var idx = '';
				$.each(CodeGoods.seItem, function() {
					idx += ',' + this.id;
				});
				idx = idx.substr(1);
				var index = layer.open({type: 2,title: '查看数据',area: ['800px', '100%'],fix: false, maxmin: true,content: Feng.ctxPath + '/Record.Customer/view?id='+idx});
				this.layerIndex = index;
			}
		}
	}


	CodeGoods.search = function() {
		CodeGoods.table.refresh({query : CodeGoods.formParams()});
	};

	CodeGoods.sd_deal = function (value) {
		if (this.check()) {
			var arr = new Array()
			$.each(CodeGoods.seItem, function() {
				var sub_item=new Array();
				sub_item.push(this.id)
				sub_item.push($("#business_income_amount_"+this.id).val());
				sub_item.push($("#pay_for_fee_"+this.id).val());
				arr.push(sub_item);
			});
			var url="{:url('admin/Record.Finance/businessIncomeSettlement')}";
			$.ajax({
				url:url,
				type:'post',
				data:{list:arr},
				dataType:'json',
				success:function(result,status,xhr){
					if(result.status==0){
						layer.msg('结算成功');
						CodeGoods.search();
					}else{
						layer.msg('请求失败');
					}
				},
				error:function(result,status,xhr){
					layer.msg('请求出错');
				}
			})
		}
	}
	$(function() {
		var defaultColunms = CodeGoods.initColumn();
		var url = location.search;
		var table = new BSTable(CodeGoods.id, Feng.ctxPath+"/Record.Finance/businessIncome"+url,defaultColunms,500);
		table.setPaginationType("server");
		table.setQueryParams(CodeGoods.formParams());
		CodeGoods.table = table.init();
	});
</script>
{/block}
